package Controller.ServicoController;

import javax.swing.JOptionPane;

import DAO.ServicoDAO;
import Entidade.Servico;
import Model.ServicoModel.ServicoConsultaModel;
import View.ServicoView.ServicoView;
import framework.mvc.GenericController;

public class ServicoConsultaController extends GenericController<Servico> {
	public ServicoConsultaController() {
		super(new ServicoConsultaModel(), new ServicoDAO());
	}

	public void novo() {
		ServicoView servicoview = new ServicoView();
		servicoview.abrir();
		view.atualizarView();
	}

	public void alterar() {
		view.atualizarModel();
		Servico servicoSelecionado = ((ServicoConsultaModel) model)
				.getServicoSelecionado();
		if (servicoSelecionado == null) {
			JOptionPane.showMessageDialog(null,
					"Selecione o Servico que deseja alterar", "Erro",
					JOptionPane.ERROR_MESSAGE);

		} else {
			ServicoView servicoView = new ServicoView();
			servicoView.getModel().setEntidade(servicoSelecionado);
			servicoView.atualizarView();
			servicoView.abrir();
			view.atualizarView();
		}
	}

	public void excluir() {
		view.atualizarModel();
		Servico servicoSelecionado = ((ServicoConsultaModel) model)
				.getServicoSelecionado();
		if (servicoSelecionado == null) {
			JOptionPane.showMessageDialog(null,
					"Selecione o Servico que deseja excluir", "Erro",
					JOptionPane.ERROR_MESSAGE);
		} else {
			if (JOptionPane.showConfirmDialog(null,
					"Deseja realmente excluir este Servico?") == JOptionPane.YES_OPTION) {
				getDao().excluir(servicoSelecionado);
				view.atualizarView();
			}
		}
	}

	public void fechar() {
		view.dispose();
	}
}
